$(function(){
//	$("#smallElem>div:nth-of-type(1) .btn:enabled").hover(function(){
//		this.firstChild.nodeValue = "选中状态";
//	},function(){
//		this.firstChild.nodeValue = "默认状态";
//	});
//	$("#smallElem>div:nth-of-type(2) label").hover(function(){
//		this.lastChild.nodeValue = "选中状态";
//	},function(){
//		this.lastChild.nodeValue = "默认状态";
//	});
//	$(".dacp-radio-group").bind("click", function(e){
//		$(this).find(":checked")
//		.parents(".dacp-radio-item").addClass("checked").find("label").text("单选选中").parents(".dacp-radio-item")
//		.siblings(".dacp-radio-item").removeClass("checked").find("label").text("单选默认");
//	});
//	$(".dacp-checkbox-group").bind("click", function(e){
//		$(this).find(":checked").parents(".dacp-checkbox-item").addClass("checked").find("label").text("复选选中");
//		$(this).find("input:not(:checked)").parents(".dacp-checkbox-item").removeClass("checked").find("label").text("复选默认");
//	});
	
	//rate
	$(".dacp-rate-heart span").click(function(){
		var $spans = $(this).parents(".dacp-rate").find("span");
		var index = $spans.index(this);
		$.each($spans, function(ind,sp) {
			if(ind < index + 1){
				$(sp).removeClass("fa-heart-o").addClass("fa-heart");
			}else{
				$(sp).removeClass("fa-heart").addClass("fa-heart-o");
			}
		});
	});
	$(".dacp-rate-star span").click(function(){
		var $spans = $(this).parents(".dacp-rate").find("span");
		var index = $spans.index(this);
		$.each($spans, function(ind,sp) {
			if(ind < index + 1){
				$(sp).removeClass("fa-star-o").addClass("fa-star");
			}else{
				$(sp).removeClass("fa-star").addClass("fa-star-o");
			}
		});
	});
	
	
	//node
	$(".dacp-node").on("click", "span" ,function(e){
		e.preventDefault();
		$(this).parent().remove();
		return false;
	});
	$(".dacp-seltree li:not(.dacp-seltree-leaf) > span:first-of-type").bind("click", function(){
		$(this).parent().toggleClass("open").siblings().removeClass("open");
	});
	
	//popover
	$(".dacp-popover-btn .btn").bind("click", function(){
		$(this).parents(".dacp-popover").remove();
	});
	$("[data-toggle='popover']").popover();
	
	//searchbox
	$(".dacp-searchbox input").focus(function(){
		$(this).parents(".dacp-searchbox").addClass("active");
	});
	$(".dacp-searchbox input").blur(function(){
		$(this).parents(".dacp-searchbox").removeClass("active");
	});
	
	//pagination
	$(".dacp-pagination").on("click", "li a", function(e){
		$(this).parents("li").addClass("active").siblings("li").removeClass("active");
		e.preventDefault();
		return false;
	});
	
	//table
	$(".dacp-table-trtitle + tr, .dacp-table-trtitle + tr + tr").hover(function(){
		var rows = $(this).parents(".dacp-table-title").find("tbody")[0].rows;
		var index = $(rows).index(this);
		$(rows[parseInt(index / 3) * 3]).addClass("active");
	},function(){
		var rows = $(this).parents(".dacp-table-title").find("tbody")[0].rows;
		var index = $(rows).index(this);
		$(rows[parseInt(index / 3) * 3]).removeClass("active");
	});
	
	//seltree
	$(".dacp-seltree .dacp-seltree-result ~ button").bind("click", function(){
		var dropdown = $(this).parents(".dacp-seltree").find(".dacp-seltree-dropdown");
		if(dropdown.css("display") === "none"){
			dropdown.css("display","inline-block");
		}else{
			dropdown.css("display","none");
		}
	});
	$(".dacp-seltree:not(.dacp-seltree-node) .dacp-seltree-leaf").bind("click", function(){
		var filterText = $(this).find("span").html().trim();
		$(this).addClass("active").parents(".dacp-seltree").find(".dacp-seltree-leaf").not(this).removeClass("active")
				.parents(".dacp-seltree").find(".dacp-seltree-dropdown").css("display", "none")
				.siblings(".dacp-input").find(".dacp-seltree-result").html(filterText);
		
	});
	$(".dacp-seltree-node .dacp-seltree-leaf").bind("click", function(){
		var filterText = $(this).find("span").html().trim();
		var newNode = $("<div class='dacp-node dacp-node-ellipse'>"+ filterText+ "<span class='fa fa-times'>&nbsp;</span></div>")
		newNode.appendTo($(this).parents(".dacp-seltree-node").find(".dacp-seltree-result"));
		$(this).addClass("active").parents(".dacp-seltree-node").find(".dacp-seltree-dropdown").css("display", "none");
	});
	$(".dacp-seltree-node").on("click", ".dacp-node span" ,function(e){
		e.preventDefault();
		$(this).parent().remove();
		return false;
	});
	
	//transfer
	$(".dacp-transfer-checkall input[type=checkbox]").change(function(){
		var checked = this.checked;
		$(this).parents(".dacp-transfer-checkall").siblings(".dacp-checkbox-group").find(":checkbox").attr("checked", checked);
	});
	
	
	
	//sidebar
	$(".dacp-sidebar .collapse").on("show.bs.collapse", function(){
		$(this).parents(".panel").addClass("active").siblings().removeClass("active");
	});
	$(".dacp-sidebar .collapse").on("hidden.bs.collapse", function(){
		$(this).parents(".panel").removeClass("active");
	});
	
	//datetimepicker
	$.fn.datetimepicker.dates['zh-CN'] = {
			days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
			daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
			daysMin:  ["日", "一", "二", "三", "四", "五", "六", "日"],
			months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
			monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
			today: "今天",
			suffix: [],
			meridiem: ["上午", "下午"]
	};
	var datetimepicker = $("#datetimepicker").datetimepicker({
		container: ".dacp-calendar",
		fontAwesome: true,
		language: "zh-CN",
        autoclose: true,
        todayBtn: true,
        pickerPosition: "bottom-right",
        isInline:true
   });
});
